{% extends "base.html" %}

{% block content %}
<div class="card">
    <div class="card-header">
        <h5 class="mb-0">选手列表</h5>
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>总排名</th>
                        <th>性别排名</th>
                        <th>组别排名</th>
                        <th>组别</th>
                        <th>参赛号</th>
                        <th>国家</th>
                        <th>官方时间</th>
                        <th>净时间</th>
                    </tr>
                </thead>
                <tbody>
                    {% for runner in runners %}
                    <tr>
                        <td>{{ runner['Overall Position'] }}</td>
                        <td>{{ runner['Gender Position'] }}</td>
                        <td>{{ runner['Category Position'] }}</td>
                        <td>{{ runner['Category'] }}</td>
                        <td>{{ runner['Race No'] }}</td>
                        <td>{{ runner['Country '] }}</td>
                        <td>{{ runner['Official Time'] }}</td>
                        <td>{{ runner['Net Time'] }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    <div class="card-footer">
        <nav>
            <ul class="pagination justify-content-center">
                <!-- 上一页 -->
                <li class="page-item {% if current_page == 1 %}disabled{% endif %}">
                    <a class="page-link" href="?page={{ current_page - 1 }}">&laquo;</a>
                </li>
                
                <!-- 第一页 -->
                <li class="page-item {% if current_page == 1 %}active{% endif %}">
                    <a class="page-link" href="?page=1">1</a>
                </li>
                
                <!-- 省略号和中间页码 -->
                {% set left_edge = 2 %}
                {% set right_edge = total_pages - 1 %}
                {% set display_range = 2 %}  {# 当前页左右显示的页数 #}
                
                {% if current_page - display_range > 2 %}
                    <li class="page-item disabled"><span class="page-link">...</span></li>
                {% endif %}
                
                {% for page in range(current_page - display_range, current_page + display_range + 1) %}
                    {% if page > 1 and page < total_pages %}
                        {% if page == current_page %}
                            <li class="page-item active">
                                <span class="page-link">{{ page }}</span>
                            </li>
                        {% else %}
                            <li class="page-item">
                                <a class="page-link" href="?page={{ page }}">{{ page }}</a>
                            </li>
                        {% endif %}
                    {% endif %}
                {% endfor %}
                
                {% if current_page + display_range < total_pages - 1 %}
                    <li class="page-item disabled"><span class="page-link">...</span></li>
                {% endif %}
                
                <!-- 最后一页 -->
                {% if total_pages > 1 %}
                    <li class="page-item {% if current_page == total_pages %}active{% endif %}">
                        <a class="page-link" href="?page={{ total_pages }}">{{ total_pages }}</a>
                    </li>
                {% endif %}
                
                <!-- 下一页 -->
                <li class="page-item {% if current_page == total_pages %}disabled{% endif %}">
                    <a class="page-link" href="?page={{ current_page + 1 }}">&raquo;</a>
                </li>
            </ul>
        </nav>
    </div>
</div>
{% endblock %} 